
const state = {
  address:JSON.parse(uni.getStorageSync('address') ||'{}') ,
  token:uni.getStorageSync('token') || '' ,
  userinfo: JSON.parse(uni.getStorageSync('userinfo') ||'{}')
  }
const mutations = {
  // 更新收货地址
  UPDATEADDRESS(state,address) {
    state.address = address
    this.commit('user/SAVEADDRESS')
  },
  // 持久化收货地址
  SAVEADDRESS(state) {
    uni.setStorageSync('address',JSON.stringify(state.address))
  },
  // 更新用户的基本信息
  UPDATEUSERINFO(state,userinfo) {
    state.userinfo = userinfo
    this.commit('user/saveUserInfo')
  },
  // 持久化用户信息
  saveUserInfo(state) {
    uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
  },
  // 更新token
  UPDATETOKEN(state,token) {
    state.token = token
    this.commit('user/saveToken')
  },
  saveToken(state) {
    uni.setStorageSync('token',state.token)
  }
}
const actions = {}

export default {
  namespaced: true,
  state,
  mutations,
  actions
}
